<?php
/**
* @author		Arunoda Susiripala
* @package		jconnect
* @copyright	Arunoda Susiripala
* @license 		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
*/ 
session_start();

include("init.php");
include("Joomla.php");

$joomla=new Joomla(
		$j_host,
		$j_path,
		$j_port,
		$appName,
		$secret
		);
		
if(isset($_REQUEST['submit'])){
	$username=$_REQUEST["username"];
	$password=$_REQUEST["password"];
		
	try{
		$joomla->login($username,$password);
		$_SESSION['username']=$username;
	}
	catch(Exception $ex){
		echo "<h2><font color='red'>". $ex->getMessage(). "</font></h2>";
	}
}else if(isset($_REQUEST['logout'])){
	$username=$_SESSION['username'];
	unset($_SESSION['username']);
	
	try{
		$joomla->logout($username);
	}
	catch(Exception $ex){
		echo "<h2><font color='red'>". $ex->getMessage(). "</font></h2>";
	}
}
?>

<html>
	<form method="POST" action="">
		username <input type="text"name="username" /><br/>
		password <input type="text"name="password" /><br/>
		<input type="submit" name="submit" value="submit" />
	</form>
	<br><br>
	<form method="POST" action="">
		<input type="submit" name="logout" value="logout" />
	</form>
</html>
